//
//  NYDetailChapterCell.m
//  NiuWaJiaoYu
//
//  Created by MinLison on 2018/1/10.
//  Copyright © 2018年 niuwaketang. All rights reserved.
//

#import "NYDetailChapterCell.h"
@interface NYDetailChapterCell ()
@property(nonatomic, strong) TTTAttributedLabel *indexLabel;
@property(nonatomic, strong) QMUIButton *iconBtn;
@property(nonatomic, strong) TTTAttributedLabel *titleLabel;
@property(nonatomic, strong) TTTAttributedLabel *timeLabel;
@end
@implementation NYDetailChapterCell
+ (CGFloat)heightForObject:(id)object identifier:(NSString *)identifier atIndexPath:(NSIndexPath *)indexPath tableView:(UITableView *)tableView
{
        return __WGHeight(50);
}
- (BOOL)shouldUpdateCellWithObject:(id)object atIndexPath:(NSIndexPath *)indexPath
{
        self.indexPath = indexPath;
        self.videoModel = object;
        return YES;
}
- (void)setVideoModel:(NYVideoModel *)videoModel
{
        _videoModel = videoModel;
        [self updateContent];
}
- (void)updateContent
{
        self.indexLabel.text = [NSString stringWithFormat:@"%2d",(int)self.indexPath.row + 1];
        self.iconBtn.selected = YES;
        self.titleLabel.text = self.videoModel.video_title;
        self.titleLabel.textColor = (self.videoModel.is_learn == 2) ? UIColorHex(0x999999) : UIColorHex(0x333333);
        self.indexLabel.textColor = (self.videoModel.is_learn == 2) ? UIColorHex(0x999999) : UIColorHex(0x333333);
        self.timeLabel.textColor =  UIColorHex(0x999999);
//        self.timeLabel.text = self.videoModel.posttime;
}
- (void)setupView
{
        [super setupView];
        UIView *contentView = [[UIView alloc] init];
        [self.contentView addSubview:contentView];
        contentView.qmui_borderPosition = QMUIBorderViewPositionBottom;
        [contentView mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.edges.equalTo(self.contentView).valueOffset([NSValue valueWithUIEdgeInsets:UIEdgeInsetsMake(0, 15, 0, 15)]);
        }];
        self.indexLabel = [self createLabel];
        self.iconBtn = [[QMUIButton alloc] qmui_initWithImage:[[UIImage wo_de_ke_cheng_bo_fang_an_niu] imageByTintColor:UIColorHex(0xCECECE)] title:nil];
        [self.iconBtn setImage:[[UIImage wo_de_ke_cheng_bo_fang_an_niu] imageByTintColor:UIColorHex(0x5396FF)] forState:(UIControlStateSelected)];
        self.titleLabel = [self createLabel];
        self.timeLabel = [self createLabel];
        self.timeLabel.textColor = UIColorHex(0x999999);
        [self.timeLabel setContentCompressionResistancePriority:(UILayoutPriorityDefaultHigh) forAxis:(UILayoutConstraintAxisHorizontal)];
        [self.titleLabel setContentCompressionResistancePriority:(UILayoutPriorityDefaultLow) forAxis:(UILayoutConstraintAxisHorizontal)];
        [contentView addSubview:self.indexLabel];
        [contentView addSubview:self.iconBtn];
        [contentView addSubview:self.titleLabel];
        [contentView addSubview:self.timeLabel];
        
        [self.indexLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(contentView);
                make.centerY.equalTo(contentView);
        }];
        [self.iconBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(self.indexLabel.mas_right).offset(__WGWidth(11));
                make.centerY.equalTo(contentView);
                make.width.height.mas_equalTo(__WGHeight(15));
        }];
        [self.titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(self.iconBtn.mas_right).offset(__WGWidth(11));
                make.centerY.equalTo(contentView);
                make.right.lessThanOrEqualTo(self.timeLabel.mas_left).offset(-__WGWidth(10));
        }];
        [self.timeLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.right.equalTo(contentView);
                make.centerY.equalTo(contentView);
        }];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
        [super setSelected:selected animated:animated];
        self.iconBtn.selected = selected;
        self.titleLabel.textColor = selected ? UIColorHex(0x5396FF) : UIColorHex(0x333333);
        self.indexLabel.textColor = selected ? UIColorHex(0x5396FF) : UIColorHex(0x333333);
        self.timeLabel.textColor =  selected ? UIColorHex(0x5396FF) : UIColorHex(0x999999);
}
- (TTTAttributedLabel *)createLabel
{
        TTTAttributedLabel *label = [[TTTAttributedLabel alloc] initWithFrame:CGRectZero];
        label.font = WGSystem13Font;
        label.textColor = UIColorHex(0x333333);
        return label;
}
@end
